package com.ruoyi.jjyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jjyh.domain.JjyhTimesrecord;
import com.ruoyi.jjyh.service.IJjyhTimesrecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 次数变动记录Controller
 * 
 * @author ruoyi
 * @date 2020-12-02
 */
@Controller
@RequestMapping("/jjyh/timesrecord")
public class JjyhTimesrecordController extends BaseController
{
    private String prefix = "jjyh/timesrecord";

    @Autowired
    private IJjyhTimesrecordService jjyhTimesrecordService;

    @RequiresPermissions("jjyh:timesrecord:view")
    @GetMapping()
    public String timesrecord()
    {
        return prefix + "/timesrecord";
    }

    /**
     * 查询次数变动记录列表
     */
    @RequiresPermissions("jjyh:timesrecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JjyhTimesrecord jjyhTimesrecord)
    {
        startPage();
        List<JjyhTimesrecord> list = jjyhTimesrecordService.selectJjyhTimesrecordList(jjyhTimesrecord);
        return getDataTable(list);
    }

    /**
     * 导出次数变动记录列表
     */
    @RequiresPermissions("jjyh:timesrecord:export")
    @Log(title = "次数变动记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JjyhTimesrecord jjyhTimesrecord)
    {
        List<JjyhTimesrecord> list = jjyhTimesrecordService.selectJjyhTimesrecordList(jjyhTimesrecord);
        ExcelUtil<JjyhTimesrecord> util = new ExcelUtil<JjyhTimesrecord>(JjyhTimesrecord.class);
        return util.exportExcel(list, "timesrecord");
    }

    /**
     * 新增次数变动记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存次数变动记录
     */
    @RequiresPermissions("jjyh:timesrecord:add")
    @Log(title = "次数变动记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JjyhTimesrecord jjyhTimesrecord)
    {
        return toAjax(jjyhTimesrecordService.insertJjyhTimesrecord(jjyhTimesrecord));
    }

    /**
     * 修改次数变动记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JjyhTimesrecord jjyhTimesrecord = jjyhTimesrecordService.selectJjyhTimesrecordById(id);
        mmap.put("jjyhTimesrecord", jjyhTimesrecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存次数变动记录
     */
    @RequiresPermissions("jjyh:timesrecord:edit")
    @Log(title = "次数变动记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JjyhTimesrecord jjyhTimesrecord)
    {
        return toAjax(jjyhTimesrecordService.updateJjyhTimesrecord(jjyhTimesrecord));
    }

    /**
     * 删除次数变动记录
     */
    @RequiresPermissions("jjyh:timesrecord:remove")
    @Log(title = "次数变动记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jjyhTimesrecordService.deleteJjyhTimesrecordByIds(ids));
    }
}
